package com.delivery.www.servlet;

import com.delivery.www.po.Comment;
import com.delivery.www.po.Message;
import com.delivery.www.po.User;
import com.delivery.www.service.ServiceImpl.CommentServiceImpl;
import com.delivery.www.service.ServiceImpl.MessageServiceImpl;

import java.util.List;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;

import static com.delivery.www.servlet.UserStorePage.storePage;

public class UserCommentPage {
    public static void commentPage(int storeId, User user) {
        CommentServiceImpl commentService = new CommentServiceImpl();
        MessageServiceImpl messageService = new MessageServiceImpl();
        Scanner scanner = new Scanner(System.in);
        List<Message> messages = messageService.getMessage(storeId);
        System.out.println("本店铺的留言如下：");
        for (Message message : messages) {
            System.out.println("====================");
            System.out.println("留言内容：" + message.getContent());
            System.out.println("====================");
        }
        List<Comment> comments = commentService.getComment(storeId);
        System.out.println("客户评论如下：");
        for (Comment comment : comments) {
            System.out.println("====================");
            System.out.println("评论id：" + comment.getCommentId());
            System.out.println("评论内容：" + comment.getContent());
            System.out.println("评论人：" + comment.getUserName());
            System.out.println("====================");
        }
        System.out.println("请输入你要进行的操作：");
        System.out.println("1.写评论");
        System.out.println("2.返回");
        int i = scanner.nextInt();
        while (i != 1 && i != 2) {
            System.out.println("输入错误！请重新输入");
            i = scanner.nextInt();
        }
        if (i == 1) {
            System.out.println("请输入评论内容：");
            String s = scanner.next();
            boolean b = commentService.doComment(storeId, user.getUserId(), s);
            if (b) {
                System.out.println("评论成功！即将跳转");
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                commentPage(storeId, user);
            }
        } else {
            storePage(user);
        }
    }
}
